/**
* JS script for Real Estate Projects Collection Management
* @author: trungdt
* @since: June 22, 2011
*/
var dm_backup_collection=-1;
var dm_des_collection=-1;

jQuery(document).ready(function(){
    // Move all projects in collection to another
    jQuery(".duanmodule_moves").click(function(){
        var host=jQuery(this);
        var id=host.attr("id");
        id=id.substring(1);
        dm_backup_collection=id;
        
        // turn selected colletion into disabled
        jQuery("#duanmodule_col_list option").each(function(){
           if (jQuery(this).val() == dm_backup_collection)
           {
               jQuery(this).attr("disabled","disabled");
           }
           else
           {
               jQuery(this).removeAttr("disabled");
           }
        });
        
        ajax_loader_show(jQuery("#t"+dm_backup_collection));
        jQuery("#t"+dm_backup_collection).fadeIn();
        jQuery(window).scrollTop(470);
        jQuery("#duanmodule_col_list").show();
        
    });
    
    // close the form button
    jQuery("#dm_move_button_close").click(function(){
        jQuery("#duanmodule_col_list").fadeOut();
        jQuery(".dmm_ajax").fadeOut();
    });
    
    // submit form
    jQuery("#dm_move_button").click(function(){
        dm_des_collection = jQuery("#des_project").val();
        
        if ((dm_backup_collection != dm_des_collection) || (dm_backup_collection > -1)){
           var t_random=Math.floor(Math.random()*9999);
           jQuery.post('index.php',{
               action:'collection_move',
               module:'duanmodule',
               sid: dm_backup_collection,
               did: dm_des_collection,
               ajax_action: 1,
               t: t_random
           }, function(data) {
               data=ajax_string_dim(data);
               alert(data);
           });
        }
        jQuery("#duanmodule_col_list").fadeOut();
        jQuery(".dmm_ajax").fadeOut();
    })
});